package com.gitee.xqxyxchy.crypto.impl;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;

import org.bouncycastle.util.encoders.Hex;

import com.gitee.xqxyxchy.crypto.CryptoParam;
import com.gitee.xqxyxchy.crypto.ICryptoService;

public class Md5Crypto implements ICryptoService {

	private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
	private static final String DEFAULT_DIGEST = "MD5";

	@Override
	public String encrypt(String originData, CryptoParam... params) {
		try {
			MessageDigest md = MessageDigest.getInstance(DEFAULT_DIGEST);
			byte[] digest = md.digest(originData.getBytes(DEFAULT_CHARSET));
			return Hex.toHexString(digest);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	@Override
	public String decrypt(String encryptedData, CryptoParam... params) {
		throw new RuntimeException("Not supported.");
	}

}
